package sys.spvisor.console.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import sys.spvisor.core.entity.project.TPushMesssage;
import sys.spvisor.core.service.project.PushMessageService;

@Controller
@RequestMapping("/pushMessage")
public class PushMessageController {
	
	@Autowired
	PushMessageService checkMessageService;
	
	//修改推送信息
	//status，审核通过还是不通过，两种类型，一个是通过，一个是未通过
	@RequestMapping("/updatePushMessage.ajax")
	public @ResponseBody Map<String,Object> updatePushMessage(int pushMessageId,String status) {
		Map<String,Object> result = new HashMap<String, Object>();
		int rows = checkMessageService.updatePushMessage(pushMessageId, status);
		String msg = "";
		if(rows == 0) {
			msg = "审核失败，请重新审核，或者联系管理员";
		}else {
			msg = "审核成功";
		}
		result.put("message", msg);
		return result;
	}
	
	//接收消息
	//第一个参数，表示用户的id,第二个参数表示状态，0表示未处理，1表示已经处理，2表示已处理未处理都查询
	//TODO
	//,int status
	@RequestMapping(value="/getMessage.ajax",method = { RequestMethod.GET })
	public @ResponseBody List<TPushMesssage> getMessage(HttpSession session) {
		Long userId =  (Long) session.getAttribute("USER_ID");
		List<TPushMesssage> lists = checkMessageService.getMessage(userId.intValue(), 0);
		return lists;
	}
	
}
